package com.webchat.admin.service;


import com.webchat.common.bean.APIResponseBean;
import com.webchat.common.bean.APIResponseBeanUtil;
import com.webchat.common.exception.BusinessException;
import com.webchat.domain.vo.request.MessageCardTemplateRequestVO;
import com.webchat.rmi.pgc.MessageCardTemplateClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

@Service
public class MessageCardTemplateService {


    @Autowired
    private MessageCardTemplateClient messageCardTemplateClient;

    /**
     * 创建或更新消息卡片模版配置
     * @param templateRequest
     * @return templateId
     */
    public String save(@RequestBody MessageCardTemplateRequestVO templateRequest) {

        APIResponseBean<String> responseBean = messageCardTemplateClient.save(templateRequest);
        if (APIResponseBeanUtil.isOk(responseBean)) {
            return responseBean.getData();
        }
        String errorMessage = "模版创建失败";
        if (responseBean != null) {
            errorMessage = responseBean.getMsg();
        }
        throw new BusinessException(errorMessage);
    }
}
